# 导入flask类
from flask import Flask, request
from werkzeug.routing import BaseConverter
from werkzeug.utils import secure_filename
import json

app = Flask(__name__)


@app.route("/")
def index():
    return f"<h1>参数传递</h1>"



# 上传完毕之后,文件大小不能超过1M
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
# 上传文件类型
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.gif']
# 上传文件路径
app.config['UPLOAD_PATH'] = 'uploads'


@app.route('/upload',methods=['POST'])
def upload():
    if request.method == 'POST':
        f = request.files.get("file")
        filename = secure_filename(f.filename)
        #f.save(os.path.join('app/static',filename))
        f.save('static/'+str(filename))
        return 'ok'
    else:
        return "上传失败"


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
